package com.classic.common.simple;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;

public class MainAbility extends Ability implements Component.ClickedListener {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        setUIContent(ResourceTable.Layout_activity_main);
        findComponentById(ResourceTable.Id_main_simple).setClickedListener(this);
        findComponentById(ResourceTable.Id_main_simple2).setClickedListener(this);
        findComponentById(ResourceTable.Id_main_simple3).setClickedListener(this);
        findComponentById(ResourceTable.Id_main_custom).setClickedListener(this);
        findComponentById(ResourceTable.Id_main_list).setClickedListener(this);
    }

    @Override
    public void onClick(Component component) {
        Intent intent = new Intent();
        Intent.OperationBuilder operationBuilder = new Intent.OperationBuilder();
        operationBuilder.withBundleName(getBundleName());
        switch (component.getId()) {
            case ResourceTable.Id_main_simple:
                operationBuilder.withAbilityName(SimpleActivity.class.getName());
                break;
            case ResourceTable.Id_main_simple2:
                operationBuilder.withAbilityName(Simple2Activity.class.getName());
                break;
            case ResourceTable.Id_main_simple3:
                operationBuilder.withAbilityName(Simple3Activity.class.getName());
                break;
            case ResourceTable.Id_main_custom:
                operationBuilder.withAbilityName(CustomActivity.class.getName());
                break;
            case ResourceTable.Id_main_list:
                operationBuilder.withAbilityName(ListActivity.class.getName());
                break;
        }
        Operation operation = operationBuilder.build();
        intent.setOperation(operation);
        startAbility(intent);
    }
}
